<?php

class CChatMessage extends Zend_Db_Table{
	
	protected $_name;
	
	protected $_primary;
	
	
	public function __construct(){
		
		$this->_name=R_PRE. "chat_messages";
		
		parent::__construct();
		
	}

	public function getRecentUser($uid){
		
		$db=$this->getAdapter();
		
		return $db->fetchAll("
			SELECT hisuid,username,MAX(messageid) FROM (
				(
					SELECT to_uid AS hisuid,messageid FROM $this->_name 
					WHERE from_uid='$uid' 
				)
				UNION ALL
				(
					SELECT from_uid AS hisuid,messageid FROM $this->_name 
					WHERE to_uid='$uid' 
				)
			) AS A  
			LEFT JOIN ".R_PRE."members ON uid=hisuid 
			GROUP BY hisuid 
			ORDER BY MAX(messageid) DESC
			");
	}
	

	
}